using System.Net;
using System.Threading.Tasks;
using Extention.ENode.Rpc.Routing;
using Extention.ENode.Rpc.Runtime.Communally.Entitys.Address;
using Extention.ENode.Rpc.Runtime.Server;

namespace Extention.ENode.Rpc.Entry
{
    public class ServerBase
    {


        /// <summary>
        /// 启动rpc服务端
        /// </summary>
        public void Start()
        {
            IpAddressModel model = ECommon.Components.ObjectContainer.Resolve<IpAddressModel>();
            //ECommon.Components.ObjectContainer.Resolve<ILoggerFactory>().AddProvider(new DefaultLoggerProvider(new DefaultLoggerConfiguration()));
            //var IpAddressModel = new IpAddressModel
            //{
            //    Ip = Setting.LocalIPAddress.ToString(),
            //    ServiceName = Setting.ServiceName,
            //    Port = Setting.BusSevicePort,
            //    HealthyCheckUrl = Setting.HealthCheckUrl,
            //    HealthyCheckPort = Setting.HealthCheckPort
            //};
            var serviceRouteManager = ECommon.Components.ObjectContainer.Resolve<IServiceRouteManager>();
            serviceRouteManager.SetBalanceAsync(model).Wait();
            var serviceHost = ECommon.Components.ObjectContainer.Resolve<IServiceHost>();
            Task.Factory.StartNew(async () =>
            {
                await serviceHost.StartAsync(new IPEndPoint(IPAddress.Parse(model.Ip),
                    model.Port));
            });
        }



    }
}